package com.chixing.day16_io;

import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;

public class WriterDemo {
    public static void main(String[] args) {
        //1.创建字符写入流对象
        Writer writer = null;
        try {
            writer = new FileWriter("f:/test1/hello1.txt",true);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        //2.写入数据
        String content = "Oh bank 你就是我心中的棉花糖 甜蜜的梦想  gkf spuergirls ";

        try {
            writer.write(content);
            writer.flush();//刷新缓冲区 将缓冲区里的字符数据写入到文件中
        } catch (IOException e) {
            throw new RuntimeException(e);
        }finally {//3.关闭流
            try {
                writer.close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

    }
}
